<template>
  <div>
    <!-- 地址 -->
    <address-info-vue ref="address"></address-info-vue>

    <!-- 购物车展示 -->
    <shop-info-vue></shop-info-vue>

    <!-- 合计 -->
    <van-submit-bar :price="allPrice*100" button-text="提交订单" @submit="onSubmit"  />
  </div>
</template>

<script>
import { Toast } from 'vant';
import addressInfoVue from "./components/addressInfo.vue";
import shopInfoVue from "./components/shopInfo.vue";
import { reqOrderAdd } from '../../http/api';
export default {
  components: {
    addressInfoVue,
    shopInfoVue,
  },
  data(){
    return {
      // 总价
      allPrice:JSON.parse(sessionStorage.getItem("orderInfo")).countmoney
    }
  },
  methods:{
    onSubmit(){
      // 地址info {}  {id:41,username:"zs"}
      if(this.$refs.address.info.id){
        reqOrderAdd({
          uid: JSON.parse(localStorage.getItem("isLogin")).uid,
          addressId:this.$refs.address.info.id,
          ...JSON.parse(sessionStorage.getItem("orderInfo"))
        }).then(res=>{
          if(res.data.code===200){
            this.$router.replace("/pay?orderId="+res.data.list.outTradeNo)
          }
        })
      }else{
        Toast("请选择收货地址")
      }
    }
  }
};
</script>

<style lang="less">
@import "../../less/index.less";
</style>